package cnpm.dao.impl;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import cnpm.dao.UserDAO;
import cnpm.entity.User;
import cnpm.util.HibernateUtil;

public class UserDAOImpl implements UserDAO{

	private SessionFactory sessionFactory;
	private Session session;
	
	public UserDAOImpl(){
		sessionFactory = HibernateUtil.getSessionFactory();
	}
	
	@Override
	public User getUser(String username) {
		User user = null;
		try{
			session = sessionFactory.openSession();
			user = (User) session.get(User.class, username);
			return user;
		}catch(HibernateException e){
			e.printStackTrace();
		}finally{
			session.close();
		}
		return user;
	}

}
